package com.wanxin.car.util.helper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;

/**
 * exception handler
 * @author lqk
 */
public class MyHandlerExceptionResolver extends AbstractHandlerExceptionResolver{

	@Override
	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		ex.printStackTrace();

		Throwable roote = ExceptionUtils.getRootCause(ex);
		String msg = roote==null?ex.getMessage():roote.getMessage();
		
		ModelAndView m = new ModelAndView();
		m.addObject("msg", msg);
		m.setViewName("error");
		return m;
	}

}
